<?php
/**
 * @package WordPress
 * @subpackage Bside
 */

if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'sidebar-left',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2>',
    ));
    register_sidebar(array(
        'name' => 'sidebar-right',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2>',
    ));
}
/**
    define some functions for bside-theme
<input type="text" value="' . the_search_query() . '" name="s" id="s" />

**/

function get_authorinfo($id='') {
global $wpdb;

if ($id && $id != '') {

// Per author info
$bs_author = get_post_meta($id, 'ai_name', true);
$bs_location = get_post_meta($id, 'ai_location', true);
$bs_bio = get_post_meta($id, 'ai_bio', true);

$authorinfo = array(
			//'id'=>$id,
			'现居住地'=>$bs_location,
			'简介'=>$bs_bio,
			'笔名'=>$bs_author);

foreach ($authorinfo as $key => $value) {
    print "$key : $value <br>\n";
}
} else {

// There was an error
$authorinfo = array(
			'error_number'=>1,
			'error_text'=>'No site_id was given');

} // end if $id

return $authorinfo;
}
/*--recent comments--*/
function bs_get_recent_comments($no_comments = 10, $comment_length = 15) {
 global $wpdb;
 $request = "SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN ('publish','static') AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $no_comments";
 $comments = $wpdb->get_results($request);
 $output = '';
 if ($comments) {
  foreach ($comments as $comment) {
   $comment_author = stripslashes($comment->comment_author);
   if ($comment_author == "") {
    $comment_author = "无名氏";
   }
   $comment_content = strip_tags($comment->comment_content);
   $comment_content = stripslashes($comment_content);
   $words=split(" ",$comment_content); 
   //$comment_excerpt = join(" ",array_slice($words,0,$comment_length));
   $comment_excerpt = cut_str($comment_content,$comment_length);
   $permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
   $url = $comment->comment_author_url;
   $post_title = $comment->post_title;
   if (empty($url)) {
    $output .= "<li>".$comment_author." 评论 "."[".$post_title."]"." 说： "."<a href='$permalink'>".$comment_excerpt."</a></li>";
   }
   else {
    $output .= "<li>"."<a href='$url' rel='external'>".$comment_author."</a>"." 评论 "."[".$post_title."]"." 说： "."<a href='$permalink'>".$comment_excerpt."</a></li>";
   }
   $output = convert_smilies($output);
  }
 } else {
  $output .= "<li>暂无评论.</li>";
 }
 echo $output;
}
   ?>
